package trinnes.oliver.unimaas.smartpentalath.control;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import trinnes.oliver.unimaas.smartpentalath.data.Cell;
import trinnes.oliver.unimaas.smartpentalath.data.Piece;

/**
 *
 * @author Oliver Trinnes
 */
public abstract class Player
{
  protected Game game;
  private Piece piece;
  private String name;
  protected int nextMove;
  protected boolean nextMoveChanged;
  private int ID;
  protected PropertyChangeSupport changeSupport;

  public Player(Game game, Piece piece, String name, int ID)
  {
    this.game = game;
    this.piece = piece;
    this.name = name;
    this.ID = ID;
    changeSupport = new PropertyChangeSupport(this);
  }

  public int getID()
  {
    return ID;
  }

  public String getName()
  {
    return name;
  }

  public void setName(String name)
  {
    this.name = name;
  }

  public Piece getPiece()
  {
    return piece;
  }

  public void setPiece(Piece piece)
  {
    this.piece = piece;
  }

  public Game getGame()
  {
    return game;
  }

  public abstract int getNextMove();

  @Override
  public String toString()
  {
    return getName() + " [" + getPiece() + "]";
  }
  
  public void setNextMove(Cell cell)
  {
    nextMove = getGame().getBoard().getCells().indexOf(cell);
    nextMoveChanged = true;
  }

  public void setNextMove(int move)
  {
    nextMove = move;
    nextMoveChanged = true;
  }

  public void setNextMoveChanged(boolean nextMoveChanged)
  {
    this.nextMoveChanged = nextMoveChanged;
  }

  public boolean isNextMoveChanged()
  {
    return nextMoveChanged;
  }

  public void addPropertyChangeListener(PropertyChangeListener listener)
  {
    changeSupport.addPropertyChangeListener(listener);
  }

  public void removePropertyChangeListener(PropertyChangeListener listener)
  {
    changeSupport.removePropertyChangeListener(listener);
  }

}
